Skip to main content

Ternary Expression

Flow-Wing supports the ? keyword to handle multiple cases.

Example Usage:

print(true ? "Hello" : "World", "\n")
print(false ? "Hello" : "World", "\n")
print(2 > 1 ? "Hello" : "World")  

Output:

Hello
World
Hello

Here, if first condition is true, Hello is printed. If first condition is false, World is printed.

Example Usage:

var x: int = (43 == 43) ? 10 : 20

Here, if first condition is true, 10 is assigned to x. If first condition is false, 20 is assigned to x.

Recommendation

It is recommended to use `(` and `)` around the condition to get expected results

Example Usage:

fun max(a: int, b: int) -> int {
  return ((a > b) ? a : b )
}
print(max(10, 20))

Output:

20

Here, if first condition is true, 10 is returned. If first condition is false, 20 is returned.

Recommendation

It is recommended to use `(` and `)` around the condition to get expected results